import unittest

from aggmon.importers.torque_accounting_log import TorqueAccountingLogImporter
from basic_types.metric import Metric


TORQUE_ACCOUNTING_LOG = """\
10/09/2013 15:49:29;Q;10663.lxt1i;queue=devel
10/09/2013 15:49:29;Q;10663.lxt1i;queue=route
10/09/2013 15:25:33;E;11;user=nectest group=nectest jobname=STDIN queue=workq ctime=1381324903 qtime=1381324903 etime=1381324903 start=1381324903 owner=nectest@lxt1i exec_host=node02/0 Resource_List.ncpus=1 Resource_List.neednodes=1 Resource_List.nodect=1 Resource_List.nodes=1 Resource_List.walltime=00:03:00 session=2495 end=1381325133 Exit_status=-10 resources_used.cput=00:00:00 resources_used.mem=83032kb resources_used.vmem=199588kb resources_used.walltime=00:03:50
10/09/2013 15:21:43;S;11;user=nectest group=nectest jobname=STDIN queue=workq ctime=1381324903 qtime=1381324903 etime=1381324903 start=1381324903 owner=nectest@lxt1i exec_host=node02/0 Resource_List.ncpus=1 Resource_List.neednodes=1 Resource_List.nodect=1 Resource_List.nodes=1 Resource_List.walltime=00:02:00
10/09/2013 15:21:43;Q;11;queue=workq
10/09/2013 15:21:03;E;10;user=nectest group=nectest jobname=STDIN queue=workq ctime=1381324624 qtime=1381324624 etime=1381324624 start=1381324626 owner=nectest@lxt1i exec_host=node02/0 Resource_List.ncpus=1 Resource_List.neednodes=1 Resource_List.nodect=1 Resource_List.nodes=1 Resource_List.walltime=00:03:00 session=2433 end=1381324863 Exit_status=-10 resources_used.cput=00:00:00 resources_used.mem=83008kb resources_used.vmem=199588kb resources_used.walltime=00:03:57
10/09/2013 15:17:06;S;10;user=nectest group=nectest jobname=STDIN queue=workq ctime=1381324624 qtime=1381324624 etime=1381324624 start=1381324626 owner=nectest@lxt1i exec_host=node02/0 Resource_List.ncpus=1 Resource_List.neednodes=1 Resource_List.nodect=1 Resource_List.nodes=1 Resource_List.walltime=00:02:00
10/09/2013 15:17:04;Q;10;queue=workq
10/09/2013 15:16:33;E;9;user=nectest group=nectest jobname=STDIN queue=workq ctime=1381324362 qtime=1381324362 etime=1381324362 start=1381324363 owner=nectest@lxt1i exec_host=node02/0 Resource_List.ncpus=1 Resource_List.neednodes=1 Resource_List.nodect=1 Resource_List.nodes=1 Resource_List.walltime=00:03:00 session=2381 end=1381324593 Exit_status=-10 resources_used.cput=00:00:00 resources_used.mem=83012kb resources_used.vmem=199588kb resources_used.walltime=00:03:50
10/09/2013 15:12:43;S;9;user=nectest group=nectest jobname=STDIN queue=workq ctime=1381324362 qtime=1381324362 etime=1381324362 start=1381324363 owner=nectest@lxt1i exec_host=node02/0 Resource_List.ncpus=1 Resource_List.neednodes=1 Resource_List.nodect=1 Resource_List.nodes=1 Resource_List.walltime=00:02:00
"""


class TorqueAccountingLogImporterTest(unittest.TestCase):
    def runTest( self ):
        importer = TorqueAccountingLogImporter()
        requests = [request for request in importer._parseTorqueAccountingLog( TORQUE_ACCOUNTING_LOG )]
        assert len( requests ) == 10
        for request in requests:
            assert isinstance( request, Metric )

suite = unittest.TestSuite()
suite.addTest( TorqueAccountingLogImporterTest() )
